﻿#region Header

/*
Remote views based on linq
By

Pascal Hauser 
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

and

Raphael Gfeller
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

*/

#endregion

#region Usings

using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace InterLinq.Test {
	/// <summary>
	/// Test serializable possibilities on xp and vista
	/// </summary>
	[TestClass]
	public class TestCompatiblity {
		#region Test Methods

		[TestMethod]
		public void TestVistaBinaryFormatterNoSerialiableObject() {
			var a = new TestNormalStruct();
			var bf = new BinaryFormatter();
			var ms = new MemoryStream();
			try {
				bf.Serialize(ms, a);
				Assert.Fail("should need Serializable attribute");
			}
			catch {
				Assert.IsTrue(true);
			}
		}

		[TestMethod]
		public void TestVistaBinaryFormatterSerialiableObject() {
			var a = new TestSerialiableStruct();
			var bf = new BinaryFormatter();
			var ms = new MemoryStream();
			try {
				bf.Serialize(ms, a);
				Assert.IsTrue(true);
			}
			catch {
				Assert.IsTrue(false);
			}
		}

		[TestMethod]
		public void TestVistaDataContractSerializerSerialiableObject() {
			var a = new TestSerialiableStruct();
			var ms = new MemoryStream();
			try {
				new DataContractSerializer(typeof(TestSerialiableStruct)).WriteObject(ms, a);
				Assert.IsTrue(true);
			}
			catch {
				Assert.IsTrue(false);
			}
		}

		[TestMethod]
		public void TestVistaDataContractSerializerNoSerialiableObject() {
			var a = new TestNormalStruct();
			var ms = new MemoryStream();
			try {
				new DataContractSerializer(typeof(TestNormalStruct)).WriteObject(ms, a);
				// -> works fine under windows vista!!! (under xp not)
				Assert.IsTrue(true);
			}
			catch {
				Assert.IsTrue(false, "works fine under windows vista!!! (under xp not)");
			}
		}

		#endregion

		#region Private Test classes

		#region Nested type: TestNormalStruct

		private struct TestNormalStruct {
		}

		#endregion

		#region Nested type: TestSerialiableStruct

		[Serializable]
		private struct TestSerialiableStruct {
		}

		#endregion

		#endregion
	}
}